<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<div class="pageContent">
    <s:form action="saveOrUpdate" cssClass="pageForm required-validate" enctype="multipart/form-data" name="saveDec" namespace="/Craft" method="post" onsubmit="return iframeCallback(this, navTabAjaxDone);">
		<div class="pageFormContent nowrap" layoutH="56">
		<s:if test="dec.decId != null">
			<s:hidden name="dec.decId"></s:hidden>
		</s:if>
		
			<dl>
				<dt><s:text name="craClass"/></dt>
				<dd>
					<s:textfield name="cra.craClass"></s:textfield>
				</dd>
			</dl>
			<dl>
				<dt><s:text name="craName"/></dt>
				<dd>
					<s:textfield name="cra.craName"></s:textfield>
				</dd>
			</dl>
			<dl>
				<dt><s:text name="craContent"/></dt>
				<dd>
					<s:textfield name="cra.craContent"></s:textfield>
				</dd>
			</dl>
			<dl>
				<dt><s:text name="craImg"/></dt>
				<dd>
				<s:file name="photoFile" onchange="selImage(this)"></s:file>
				</dd>
			</dl>
			<dl>
				<dt></dt>
				<dd>
				<!--<img src="<s:url action='../download/download.action?fileName=%{#cra.craImg}' />" valign="middle" height="200px"></img> -->
					<img alt="" id="img" src="../download/execute.action?fileName=${cra.craImg}" width="200px"> 
				</dd>
			</dl>

		</div>
		<div class="formBar">
			<ul>
				<!--<li><a class="buttonActive" href="javascript:;"><span>保存</span></a></li>-->
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div></li>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
				</li>
			</ul>
		</div>
	</s:form>
</div>
<script type="text/javascript">

	function selImage(o) {
		document.getElementById("img").src = getFullPath(o);
	}

	function getFullPath(node){
	 var imgURL = "";
	    try{
	        var file = null;
	        if(node.files && node.files[0] ){
	            file = node.files[0];
	        }else if(node.files && node.files.item(0)) {
	            file = node.files.item(0);
	        }
	        //Firefox 因安全性问题已无法直接通过input[file].value 获取完整的文件路径
	        try{
	            //Firefox7.0
	            imgURL =  file.getAsDataURL();
	            //alert("//Firefox7.0"+imgRUL);
	        }catch(e){
	            //Firefox8.0以上
	            imgURL = window.URL.createObjectURL(file);
	            //alert("//Firefox8.0以上"+imgRUL);
	        }
	    }catch(e){      
	        //支持html5的浏览器,比如高版本的firefox、chrome、ie10
	        if (node.files && node.files[0]) {
	            var reader = new FileReader();
	            reader.onload = function (e) {
	                imgURL = e.target.result;
	            };
	            reader.readAsDataURL(node.files[0]);
	        }
	    }
	    return imgURL;
	}
</script>

